﻿using System;
using System.Collections.Generic;
using System.Text;



using System.IO;

namespace FinancialAnalytic.BusinessLogic
{
    public class MarketDataDownloader : AbstractDataDownloader
    {
        public StocksData GetStockData(string stockCode)
        {

            StocksData stockData = new StocksData();

            string marketUrl = @"http://in.finance.yahoo.com/d/quotes.csv?s=" + stockCode +
                    "&f=sl1d1t1c1ohgvj1pp2owern&e=.csv";

            string history = String.Empty;
            history = HistoryData(marketUrl);
            history = history.Replace("\"", "");
            string[] stockDataContents = history.Split(',');

            stockData.Symbol = stockCode;
            stockData.Last = stockDataContents[1];
            stockData.Date = stockDataContents[2];
            stockData.Time = stockDataContents[3];
            stockData.Change = stockDataContents[4];
            stockData.Open = stockDataContents[5];
            stockData.High = stockDataContents[6];
            stockData.Low = stockDataContents[7];
            stockData.Volume = stockDataContents[8];
            stockData.MarketCapital = stockDataContents[9];
            stockData.PreviousClose = stockDataContents[10];
            stockData.PctChange = stockDataContents[11];
            stockData.AnnRange = stockDataContents[13];
            stockData.Earnings = stockDataContents[14];
            stockData.PERatio = stockDataContents[15];

            return stockData;
          
        }

    }
}
